<?php

class Document extends AppModel
{

    var $name = 'Document';
    var $displayField = 'name';
    var $order = array('Document.name' => 'ASC');
    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        'Product' => array(
            'className' => 'Product',
            'foreignKey' => 'product_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Employee' => array(
            'className' => 'Employee',
            'foreignKey' => 'employee_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
    var $hasAndBelongsToMany = array(
        'Potentialactivity' => array(
            'className' => 'Potentialactivity',
            'joinTable' => 'potentialactivities_documents',
            'foreignKey' => 'document_id',
            'associationForeignKey' => 'potentialactivity_id',
            'unique' => true,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'finderQuery' => '',
            'deleteQuery' => '',
            'insertQuery' => ''
        ),
        'Useractivity' => array(
            'className' => 'Useractivity',
            'joinTable' => 'useractivities_documents',
            'foreignKey' => 'document_id',
            'associationForeignKey' => 'useractivity_id',
            'unique' => true,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'finderQuery' => '',
            'deleteQuery' => '',
            'insertQuery' => ''
        )
    );
    var $validate = array(
        'name' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'required' => true,
                'allowEmpty' => false,
                'message' => 'Please enter name'
            ),
            'minLength' => array(
                'rule' => array('minLength', 2),
                'message' => 'Name should be atleast 2 characters long'
            )
        ),
        'product_id' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please choose the product'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'message' => 'Please choose the product'
            ),
            'greaterThan' => array(
                'rule' => array('comparison', '>=', 1),
                'message' => 'Please choose the product'
            )
        ),
        'path' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please enter path for this document'
            )
        ),
        'validfrom' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please choose/enter the "valid from" date in dd-mm-yyyy format'
            ),
            'date' => array(
                'rule' => array('date', 'dmy'),
                'message' => 'Please enter a valid date'
            )
        ),
        'validto' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please choose/enter the "cost valid to" date in dd-mm-yyyy format'
            ),
            'date' => array(
                'rule' => array('date', 'dmy'),
                'message' => 'Please enter a valid date'
            )
        ),
        'employee_id' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'required' => true,
                'message' => 'Invalid employee id'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'message' => 'Invalid employee id'
            )
        )
    );

}
?>